#include "ShootingEnemy.h"
#include "../Player.h"

CShootingEnemy::CShootingEnemy(void)
{

}

CShootingEnemy::~CShootingEnemy(void)
{

}

//Inherited from CEntity///////////////////////////////
void CShootingEnemy::Update (float fElapsedTime)
{

}

void CShootingEnemy::Render (void)
{

}

RECT CShootingEnemy::GetRect(void) const
{
	RECT temp = { 0,0,0,0 };
	return temp;
}

bool CShootingEnemy::CheckCollision( IEntity* pOther )
{
	return true;
}
///////////////////////////////////////////////////////
void CShootingEnemy::HandleEvent(CNEvent* pEvent)
{
		if(pEvent->GetEventID() == "take damage")
	{
		this->m_nHealth -= 35;
		CPlayer* pPlayer = dynamic_cast<CPlayer*>(this->m_pTarget);
		pPlayer->SetCurrentHits(pPlayer->GetCurrentHits()+1);
		this->SetVelX(-(this->GetVelX()+10));
	}
	if(pEvent->GetEventID() == "Return")
	{
		CEventSystem* self = CEventSystem::GetInstance();
		self->SendEvent("TakePlayerDamage");
		m_cAniInfo.SetName("EShootWalk");	
		m_cAniInfo.SetNext("EShootAttack");
		m_cAniInfo.SetTime(0);
		m_cAniInfo.SetFrame(0);
		m_battack=false;


	}
}

bool CShootingEnemy::Init(CEntity* pTarget,int x,int y,int speedset)
{
		if(pTarget->GetType() != OBJ_PLAYER)
		return false;
		else
		{
	m_pES = CEventSystem::GetInstance();
	m_pTM	= CSGD_TextureManager::GetInstance();
	m_pXA	= CSGD_XAudio2::GetInstance();
	m_pD3D	= CSGD_Direct3D::GetInstance();
	m_pMS	= CMessageSystem::GetInstance();
	m_pAM	= CAnimationManager::GetInstance();

	CEventSystem::GetInstance()->RegisterClient("take damage", this);
	CEventSystem::GetInstance()->RegisterClient("Return", this);


	//Set planned animations
	this->m_cAniInfo.SetName("EShootWalk");		 //Specific to class of enemy
	this->m_cAniInfo.SetNext("EShootAttack");	 //Specific to class of enemy
	this->m_cAniInfo.SetTime(0);			 //Specific to class of enemy
	this->m_cAniInfo.SetFrame(0);			 //Specific to class of enemy

	this->SetHeight(m_pAM->GetCHeight(this->m_cAniInfo));
	this->SetWidth(m_pAM->GetCWidth(this->m_cAniInfo));

	this->SetFacing(true);
	this->SetDensity(1);

	this->SetPosX(float(x));
	this->SetPosY(float(y));//(float)CGame::GetInstance()->GetHeight() - this->GetHeight()-500);
	this->m_eType = OBJ_SHOOT_ENEMY;
	this->SetVelX(0);
	this->SetVelY(0);
	this->m_pTarget = pTarget;
	this->m_nHealth = 100;
	this->m_nSpeedoffset =speedset;
	this->OnPlatform(false);

	this->m_fTimer =0;
	this->m_fAttackTimer =0.75f;
	this->m_battack=false;
	}
	return true;
		
}
